#include "Socket.hpp"
#include <memory>
#include <iostream>
#include "Log.hpp"
#include "TcpServer.hpp"
#include "http_protocol.hpp"

void Usage(const std::string &proc)
{
    std::cout << "格式：" << proc << " port" << std::endl;
}
std::string HandlerRequest(std::string &packages)
{
    HttpRequest req;
    req.DeSerialize(packages);
    req.Debug();


    std::string content = "<html><h1>hello http</h1></html>";
    std::string httpstatusline = "Http/1.0 200 OK\r\n";
    std::string httpheader = "Content-Length: " + std::to_string(content.size()) + "\r\n";
    httpheader += "\r\n";

    std::string httpresponse = httpstatusline + httpheader + content;
    return httpresponse;

}
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[1]);
        return usage_err;
    }
    uint16_t serverport = std::stoi(argv[1]);

    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(serverport, HandlerRequest);
    tsvr->Start();
}